package com.example.health_life;

public class Response <T>{
    private int code;
    private T data;
    private boolean success;
    private String message;

    public static <K> Response<K>   newSuccess(K data){
        Response<K> response = new Response<>();
        response.setCode(200);
        response.setSuccess(true);
        response.setData(data);
        return response;
    }

    public static <K> Response<K> newFail(String message){
        Response<K> response = new Response<>();
        response.setCode(500);
        response.setSuccess(false);
        response.setMessage(message);
        response.setData(null);
        return response;
    }

    public static Response<Integer> newError(String msg) {
        Response<Integer> response = new Response<>();
        response.setCode(501);
        response.setSuccess(false);
        response.setMessage(msg);
        response.setData(null);
        return response;
    }

//    public static <K> Response<K> fail(String message){
//        Response<K> response = new Response<>();
//        response.setSuccess(false);
//        response.setMessage(message);
//        return response;
//    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
